package com.example.wonderfulradish;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 陈勇劲 on 2017/10/1.
 */

public class PagerViewAdapter extends PagerAdapter{
    private ArrayList<View> pageview;

    public PagerViewAdapter(){

    }

    public PagerViewAdapter(ArrayList<View> pageview) {
        super();
        this.pageview = pageview;//构造方法，参数是我们的页卡，这样比较方便。
    }

    @Override
    //获取当前窗体数
    public int getCount() {
        return pageview.size();
    }

    @Override
    //判断是否由对象生成界面
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    //使从ViewGroup中移除当前View
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        super.destroyItem(container, position, object);

        container.removeView(pageview.get(position));
    }

    //返回一个对象，这个对象表明了PagerAdapter适配器选择哪个对象放在当前的View
    public Object instantiateItem(ViewGroup container, int position){
        container.addView(pageview.get(position));
        return pageview.get(position);
    }
}
